// 不带参数的装饰器
function FirstClassDecorator(targetClass: typeof CustomerService) {
    let targetClassObj = new targetClass();
    // targetClassObj.buy();
    console.log("targetClass.name:", targetClass.name);
}
function SecondClassDecorator(targetClass: any) {
    let targetClassObj = new targetClass();
    targetClassObj.buy();
    console.log("targetClass.name:", targetClass.name);
}

function fn3(targetClassPrototype: any, methodName: string , methodDec: PropertyDescriptor) {
    const fn = methodDec.value;
    methodDec.value = function (...args: any[]) {
        console.log("前置拦截");
        fn.call(this, ...args); 
        console.log("后置拦截");
    }
};

function FnArg(aaa: any, bbb: any, ccc: any) {
        aaa.a = "asdf"
        console.log({aaa, bbb, ccc});
}

@FirstClassDecorator
class CustomerService {
    name: string = "下单"
     constructor() {

    }
    @fn3
    buy(@FnArg a: string) {
        console.log(this);
        
        // console.log(this.name + "购买", a);
    }
    placeOrder(a: string) {//下单
        console.log(this.name + "下单购买");
        return a;
    }
}

setTimeout(() => {
    const test = new CustomerService()
    console.log(test.buy);
    
    setTimeout(() => {
        test.buy("a")
    }, 1000);
}, 1000);
// function fn1(fn: () => void) {
//     console.log(fn);
//     return fn;
// };

// function fn1(target: any, fn: string, methodDec: PropertyDescriptor) {
//     console.log(fn);
//     return fn;
// };

// @fn1
// const fn2 = () => {
//     console.log("fn2");
    
// };
